package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;


/**
 * Created with IntelliJ IDEA.
 * User: carapka
 * Date: 19.10.12
 * Time: 1:09
 * To change this template use File | Settings | File Templates.
 */
public class InternalPage extends AnyPage

{
    @FindBy(xpath = "//div[@id='wrapper']/header/div/nav/ul/li[4]/a")
    public WebElement menuLogoutLink;

    @FindBy(xpath = "//div[@id='wrapper']/header/div/nav/ul/li[2]/a")
    public WebElement menuMyProfileLink;

    @FindBy(xpath = "//div[@id='wrapper']/header/div/nav/ul/li[3]/a")
    public WebElement menuUserManagementLink;

    public boolean isOnThisPage() {
        return menuLogoutLink.isDisplayed();
    }

    @FindBy(xpath = "//div[@id='content']/section/nav/ul/li/div/div/a/img")
    public WebElement addMovie;

    @FindBy(xpath = "//div[@id='content']/section/nav/ul/li[2]/div/div/a/img")
    public WebElement updMovie;

    @FindBy(xpath = "//div[@id='content']/section/nav/ul/li[3]/div/div/a/img")
    public WebElement expMovie;

    @FindBy(id = "q")
    public WebElement qSearch;


    public UserPage menuProfile() {
        menuMyProfileLink.click();
        return MyPageFactory.getPage(driver, UserPage.class);
    }

    public void logout() {
        menuLogoutLink.click();
        wait_().until(alertIsPresent()).accept();
    }

    @Override
    void tryToOpen() {
        MyPageFactory.getPage(driver, LoginPage.class).login("admin", "admin");
    }

    public UsersPage goToManagment() {
        menuUserManagementLink.click();
        return MyPageFactory.getPage(driver, UsersPage.class);
    }


}
